package com.zego.wawaji.ui.bean.wawa;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 娃娃信息
 * Created by Su on 2017/11/28.
 */
public class Wawa extends BaseData implements Parcelable {
    private int id;       // 娃娃id
    private String name;  // 娃娃昵称
    private String img;      // 娃娃展示图
    private double cost;  // 娃娃价格
    private long haveNum;     // 现存数量
    private long takeNum;     // 被抓走数量
    private int status;      // 状态 1正常 2关闭 3删除
    private int exchange;    // 娃娃可兑换娃娃币数量
    private int sortId;
    private String createTime;
    private int amountWwCoin; // 碎片： 原价

    // 合成娃娃
    private int pr;       // 娃娃增加的合成概率 (0-100)
    private String remark;// 娃娃介绍； 图鉴说明
    private String bigImg; // 图鉴中的娃娃大图展示
    private int wwType;   // 娃娃种类： -1：娃娃碎片  0： 小娃娃  1：大娃娃

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.setId(jsonObject.optInt("Id"));
        this.setName(jsonObject.optString("Name"));
        this.setImg(jsonObject.optString("Img"));
        this.setCost(jsonObject.optDouble("Cost"));
        this.setHaveNum(jsonObject.optLong("HaveNum"));
        this.setTakeNum(jsonObject.optLong("TakeNum"));
        this.setStatus(jsonObject.optInt("Status"));
        this.setSortId(jsonObject.optInt("SortId"));
        this.setExchange(jsonObject.optInt("Exchange"));
        this.setCreateTime(jsonObject.optString("CreateTime"));

        this.amountWwCoin = jsonObject.optInt("AmountWwCoin");
        this.pr = jsonObject.optInt("Pr");
        this.remark = jsonObject.optString("Remark");
        this.wwType = jsonObject.optInt("WwType");
        this.bigImg = jsonObject.optString("BigImg");
    }

    // 是否是合成材料
    public boolean isMaterial() {
        return wwType == -1;
    }

    // 是否可合成其他娃娃
    public boolean canSynth() {
        return wwType == -1 || wwType == 0;
    }

    // 是否是大娃娃
    public boolean isBig() {
        return wwType != -1 && wwType != 0;
    }

    public int getAmountWwCoin() {
        return amountWwCoin;
    }

    public int getPr() {
        return pr;
    }

    public String getRemark() {
        return remark;
    }

    public String getBigImg() {
        return bigImg;
    }

    public int getExchange() {
        return exchange;
    }

    public void setExchange(int exchange) {
        this.exchange = exchange;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public long getHaveNum() {
        return haveNum;
    }

    public void setHaveNum(long haveNum) {
        this.haveNum = haveNum;
    }

    public long getTakeNum() {
        return takeNum;
    }

    public void setTakeNum(long takeNum) {
        this.takeNum = takeNum;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getSortId() {
        return sortId;
    }

    public void setSortId(int sortId) {
        this.sortId = sortId;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public Wawa() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.name);
        dest.writeString(this.img);
        dest.writeDouble(this.cost);
        dest.writeLong(this.haveNum);
        dest.writeLong(this.takeNum);
        dest.writeInt(this.status);
        dest.writeInt(this.exchange);
        dest.writeInt(this.sortId);
        dest.writeString(this.createTime);
        dest.writeInt(this.pr);
        dest.writeString(this.remark);
        dest.writeInt(this.wwType);
        dest.writeString(this.bigImg);
    }

    protected Wawa(Parcel in) {
        this.id = in.readInt();
        this.name = in.readString();
        this.img = in.readString();
        this.cost = in.readDouble();
        this.haveNum = in.readLong();
        this.takeNum = in.readLong();
        this.status = in.readInt();
        this.exchange = in.readInt();
        this.sortId = in.readInt();
        this.createTime = in.readString();
        this.pr = in.readInt();
        this.remark = in.readString();
        this.wwType = in.readInt();
        this.bigImg = in.readString();
    }

    public static final Creator<Wawa> CREATOR = new Creator<Wawa>() {
        @Override
        public Wawa createFromParcel(Parcel source) {
            return new Wawa(source);
        }

        @Override
        public Wawa[] newArray(int size) {
            return new Wawa[size];
        }
    };
}
